﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Infrastructure.Crosscutting.Comm.Service
{
    public class RandService
    {
        /// <summary>
        /// 
        /// </summary>
        static readonly string codeSerial = "2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,U,V,W,X,Y,Z";

        /// <summary>
        /// Rands the code.
        /// </summary>
        /// <param name="codeLen">The code len.</param>
        /// <returns></returns>
        public static string RandCode(int codeLen)
        {
            if (codeLen == 0)
            {
                codeLen = 4;
            }
            string[] arr = codeSerial.Split(',');
            string code = "";
            int randValue = -1;
            Random rand = new Random(unchecked((int)DateTime.Now.Ticks));
            for (int i = 0; i < codeLen; i++)
            {
                randValue = rand.Next(0, arr.Length - 1);

                code += arr[randValue];
            }
            return code;
        }
    }
}
